//
//  ZJMainViewController.m
//  iosFramework
//
//  Created by Farben on 2020/8/5.
//  Copyright © 2020 Farben. All rights reserved.
//

#import "ZJMainViewController.h"
#import "ZJMacroFile.h"
#import "JLRoutes.h"
#import "ReactiveCocoa.h"
#import "RoutesMediator.h"
#import "ZJDetailViewController.h"
#import "ZJRouteTool.h"
#import "WHToast.h"
#import "ZZH_JumpButton.h"





@interface ZJMainViewController ()<UITableViewDelegate,UITableViewDataSource,ZZH_JUMPBUTTONDELEGATE>


@property (nonatomic , strong)UIButton *centerButton;
@property (nonatomic , strong)UITableView *tableView;
@property (nonatomic , strong)NSArray *titleArray;
@property (nonatomic , strong)ZZH_JumpButton *animationButton;

@end

@implementation ZJMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化
    self.view.backgroundColor = UIColor.yellowColor;
//    [self.view addSubview:self.centerButton];
    [self setNavigationBarTitleColor:UIColor.blackColor];
    [self setTitle:@"资讯"];
    
    [self.view addSubview:self.tableView];
    //下拉
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.tableView.mj_header endRefreshing];
            [WHToast showMessage:@"刷新完成" duration:1 finishHandler:^{
                
            }];
        });
    }];
    
    
    
    [self.viewModel getNetWorkWithParameter:@{} withreturnBlock:^(id  _Nonnull obj) {
        NSLog(@"%@",obj);
           //mian queue UI
            
    }];
    
    [self.view addSubview:self.animationButton];
    
    
    
//    [[self.centerButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
//        [[ZJRouteTool Share] pushViewController:[[threeViewController alloc] init]];
//    }];
    
    
}



-(ZZH_JumpButton*)animationButton{
    if(!_animationButton){
        _animationButton = [ZZH_JumpButton buttonWithType:UIButtonTypeCustom];
        _animationButton.delegate = self;
        _animationButton.bounds = CGRectMake(0, 0, 50, 50);
        _animationButton.center = CGPointMake(self.view.frame.size.width - 60, 400);
        _animationButton.backgroundColor = [UIColor orangeColor];
    }
    return _animationButton;
}


-(UIButton*)centerButton{
    if(!_centerButton){
        _centerButton  = [UIButton buttonWithType:UIButtonTypeCustom];
        _centerButton.frame = CGRectMake(0, 0, 70, 30);
        _centerButton.center = CGPointMake(Main_Screen_Width/2.f, Main_Screen_Height/2.f);
        [_centerButton setTitle:@"当前的按钮" forState:UIControlStateNormal];
    }
    return _centerButton;
}

-(UITableView*)tableView{
    if(!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.tableFooterView = [[UIView alloc]init ];
        
    }
    return _tableView;
}




#pragma mark - buttonDelegate
-(void)jumpClick:(NSInteger)ClickIndex{
    NSLog(@"index --- %ld",(long)ClickIndex);
}


#pragma mark - tableViewDelegate
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellStr = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];
    if(cell==nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellStr];
    }
    cell.textLabel.text = self.titleArray[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.row) {
        case 0:
            [self.viewModel getNetWorkWithParameter:@{} withreturnBlock:^(id  _Nonnull obj) {
                [WHToast showSuccessWithMessage:@"网络请求成功" duration:2 finishHandler:^{
                    NSLog(@"成功信息显示完成");
                }];
                
            }];
            break;
        case 1:{
            [ZJNetworking clearCaches];
            [WHToast showSuccessWithMessage:@"清理缓存" duration:2 finishHandler:^{
                
            }];
        }break;
        
        case 2:{
            BaseViewController *vc = [[ZJRouteTool Share]getViewControllerWithName:@"ZJDetailViewController"];
            [[ZJRouteTool Share]pushViewController:vc];
        }break;
        
        case 3:{
            BaseViewController *vc = [[ZJRouteTool Share]getViewControllerWithName:@"ZJDetailViewController"];
            [[ZJRouteTool Share]pushViewController:vc withPatameter:@{@"key1":@"value1",@"key2":@"value2",@"key3":@"value3"}];
        }break;
            
        default:{
            
        }
            break;
    }
    
}


-(NSArray*)titleArray{
    if(!_titleArray){
        _titleArray =  @[@"【网络请求】",@"【网络请求-清理缓存】",@"【Push 无参数】",@"【Push 有参数】",@"【动画】"];
    }
    return _titleArray;
}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
